import { getUUID } from '@/utils'
import $config from '@/config'
import { ElementModel } from './Element'

const defaultStyle = {
  backgroundColor: '#ffffff',
  backgroundImage: '',
  backgroundSize: 'cover',
  width: $config.canvasPCWidth,
  height: $config.canvasPCHeight
}
export class SceneModel {
  uuid = '';
  name = '';
  duration = '10';
  elements = [];
  propsValue = {};
  commonStyle = {};
  coverUrl = '';
  // 背景音乐
  constructor(model = {}) {
    this.uuid = model.uuid || getUUID()
    this.commonStyle = { ...defaultStyle, ...model.commonStyle }
    this.propsValue = model.propsValue ? { ...model.propsValue } : {}
    this.name = model.name || ''
    this.duration = model.duration || '10'
    this.coverUrl = model.coverUrl || ''
    this.elements = []
    if (model.elements && model.elements.length) {
      model.elements.forEach((item, idx) => {
        this.elements.push(new ElementModel({
          ...item, uuid: ''
        }, { ...item.commonStyle }))
      })
    }
  }
};
